add more fields to SerializedDependency
authorAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 17 Dec 2015 18:50:11 +0000 (21:50 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 17 Dec 2015 22:53:27 +0000 (01:53 +0300)
src/cargo/core/dependency.rs

index 1788a1fb78e80343298b569c8bcfe98a81c2cb0d..ce538d964a39c16d34341122187d6e8dcd287b9a 100644 (file)
@@ -33,16 +33,29 @@ pub struct Dependency {
 
 
 #[derive(RustcEncodable)]
-struct SerializedDependency {
-    name: String,
-    req: String
+struct SerializedDependency<'a> {
+    name: &'a str,
+    source: &'a SourceId,
+    req: String,
+    kind: Kind,
+
+    optional: bool,
+    uses_default_features: bool,
+    features: &'a [String],
+    target: &'a Option<&'a str>,
 }
 
 impl Encodable for Dependency {
     fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
         SerializedDependency {
-            name: self.name().to_string(),
-            req: self.version_req().to_string()
+            name: self.name(),
+            source: &self.source_id(),
+            req: self.version_req().to_string(),
+            kind: self.kind(),
+            optional: self.is_optional(),
+            uses_default_features: self.uses_default_features(),
+            features: self.features(),
+            target: &self.only_for_platform(),
         }.encode(s)
     }
 }
@@ -54,6 +67,16 @@ pub enum Kind {
     Build,
 }
 
+impl Encodable for Kind {
+    fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
+        match *self {
+            Kind::Normal => None,
+            Kind::Development => Some("dev"),
+            Kind::Build => Some("build"),
+        }.encode(s)
+    }
+}
+
 impl DependencyInner {
     /// Attempt to create a `Dependency` from an entry in the manifest.
     pub fn parse(name: &str,
@@ -235,4 +258,3 @@ impl Dependency {
         self.inner.matches_id(id)
     }
 }
-